package com.kafkacode.producer;

import com.kafkacode.model.User;
import com.kafkacode.utils.JSONUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;


import java.util.Date;

@Component
public class EventProducer {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;
    public void sendEvent() {
        for (int i = 0; i < 125; i++) {
            User user = User.builder()
                    .id(i)
                    .name("kafka"+i)
                    .birthday(new Date())
                    .phone("12345678901"+i)
                    .build();
            String userJson = JSONUtils.toJSONString(user);
            kafkaTemplate.send("batchTopic","k"+i,userJson);
        }
    }

}
